package com.ksd1.notes.markdown;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class Markdown {

    public static final int MD_FMT_TEXT = 0;
    public static final int MD_FMT_HEADER1 = 1;//一级标题
    public static final int MD_FMT_HEADER2 = 2;//二级标题
    public static final int MD_FMT_HEADER3 = 3;//三级标题
    public static final int MD_FMT_QUOTE = 4;//引用
    public static final int MD_FMT_ITALIC = 5;//斜体
    public static final int MD_FMT_BOLD = 6;//加粗
    public static final int MD_FMT_CENTER = 7;//居中
    public static final int MD_FMT_UNORDER_LIST = 8;//无序列表
    public static final int MD_FMT_ORDER_LIST = 9;//有序列表
    public static final int MD_FMT_LINK = 10;//链接


    /**
     * 一个单词
     */
    public static class MDWord {
        public static final MDWord NULL = new MDWord(null, 0, Markdown.MD_FMT_TEXT);
        public final String mRawContent;//待添加样式的字符串
        public final int mLength;//长度
        public final int mFormat;//样式

        /**
         * @param rawContent
         * @param length
         * @param format
         */
        public MDWord(String rawContent, int length, int format) {
            mRawContent = rawContent;
            mLength = length;
            mFormat = format;
        }
    }


    /**
     * 一行
     */
    public static class MDLine {

        public final String mLineContent;

        /**
         * 得到一个mDWord数组：如
         * [
         *  {"字符串1", "长度", 格式化形式}
         *  {"字符串2", "长度", 格式化形式}
         *  ...
         * ]
         * */
        public List<MDWord> mMDWords = new ArrayList<MDWord>();

        public int mFormat = Markdown.MD_FMT_TEXT;//整行的格式化内容

        //初始化mLineContent
        public MDLine(String lineContent) {
            mLineContent = lineContent;
        }

        /**
         * @return 返回原始字符串
         */
        public String getRawContent() {
            StringBuilder builder = new StringBuilder();
            for (MDWord word : mMDWords) {
                builder.append(word.mRawContent);
            }
            return builder.toString();
        }
    }

    public static abstract class MDParser {
        public abstract MDWord parseLineFmt(String content);

        public abstract MDWord parseWordFmt(String content);
    }
}
